# docker buildx build -t swr.cn-central-221.ovaijisuan.com/taichu-studio/kubeflow-dashboard:20231201 -f install/docker/Dockerfile --platform=linux/arm64,linux/amd64  . --push
# docker build -t swr.cn-central-221.ovaijisuan.com/taichu-studio/kubeflow-dashboard:3128ac8c -f install/docker/Dockerfile .

FROM swr.cn-central-221.ovaijisuan.com/taichu-studio/kubeflow-dashboard-base-py39:v1 as builder

WORKDIR /home/myapp

RUN rm -rf myapp
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple nuitka==1.8.6
COPY myapp /home/myapp/myapp
ENV PATH=/home/myapp/myapp/bin:$PATH
ENV PYTHONPATH=/home/myapp:/kubeflow/src/pipelines/sdk/python/:$PYTHONPATH

USER root

# 加密项目
RUN nuitka3 --module  --nofollow-imports --no-pyi-file --remove-output --include-module=myapp myapp
# 保护myapp/create_db.py文件，不被删除
RUN cp myapp/create_db.py create_db.py.bak && mv myapp/migrations migrations-bak
# 删除所有的 __pycache__ 文件夹 , 删除所有的 *.pyc *.py 文件
RUN find myapp -name "__pycache__" | xargs rm -rf && find myapp -name "*.pyc" | xargs rm -rf  && find myapp -name "*.py" | xargs rm -rf
# 删除所有的 空目录
RUN find myapp -type d -empty | xargs rm -rf && find myapp -type d -empty | xargs rm -rf
RUN mv create_db.py.bak myapp/create_db.py && mv migrations-bak myapp/migrations

COPY myapp/gunicorn_config.py /home/myapp/gunicorn_config.py

FROM swr.cn-central-221.ovaijisuan.com/taichu-studio/kubeflow-dashboard-base-py39:v1

WORKDIR /home/myapp

COPY install/docker/requirements.txt .
COPY install/docker/docker-add-file/config.ini /usr/local/lib/python3.9/dist-packages/modelarts/config/config.ini
COPY install/docker/docker-add-file/constant.py /usr/local/lib/python3.9/dist-packages/modelarts/constant.py
RUN rm -rf myapp && pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn


COPY install/docker/docker-add-file/rest.py /usr/local/lib/python3.9/dist-packages/kubernetes/client/rest.py
COPY install/docker/docker-add-file/__init__.py /usr/local/lib/python3.9/dist-packages/marshmallow_enum/__init__.py
COPY install/docker/docker-add-file/kfp/_pipeline.py  /kubeflow/src/pipelines/sdk/python/kfp/dsl/_pipeline.py
COPY install/docker/docker-add-file/kfp/compiler.py   /kubeflow/src/pipelines/sdk/python/kfp/compiler/compiler.py



COPY --from=builder /home/myapp /home/myapp
#COPY myapp/static/appbuilder/frontend /data/web/frontend
ENV PATH=/home/myapp/myapp/bin:$PATH
ENV PYTHONPATH=/home/myapp:/kubeflow/src/pipelines/sdk/python/:$PYTHONPATH

USER root
COPY myapp/entrypoint.sh /entrypoint.sh

# 清理缓存
#RUN apt-get clean && pip cache purge && apt-get autoremove -y